import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:get/get.dart';
import 'package:gameplay_flutter/lib_user/user_manager.dart';
import 'package:gameplay_flutter/m_login/os_login_page.dart';

import '../../lib_baseview/root_page.dart';
import '../../resource/language/generated/l10n.dart';

class DialogManager {
  static void showLogoutDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (context) => Center(
        child: Container(
          width: 288,
          height: 130,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8),
          ),
          child: Column(
            children: [
              const SizedBox(height: 17),
              T.current.me2_log_out.text(
                fontSize: 18,
                color: Colors.black,
                weight: TextFontWeight.regular,
              ),
              SizedBox(height: 12.h),
              T.current.me2_sure_out.text(
                fontSize: 12.sp,
                color: const Color(0xFFA8A8A8),
                weight: TextFontWeight.regular,
              ),
              Spacer(),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: TextButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: T.current.me_edit_cancel.text(
                        fontSize: 16,
                        color: const Color(0xFFC1C1C1),
                        weight: TextFontWeight.regular,
                      ),
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: TextButton(
                      onPressed: () {
                        Navigator.of(context).pop(); // 关闭对话框
                        // 执行退出操作
                        // Get.offAll(
                        //   () => OSLoginPage(),
                        //   predicate: (route) => false,
                        // );

                        // /// 跳转到首页
                        // rootNavigatorState.currentState?.pushReplacement(
                        //   MaterialPageRoute(
                        //     builder: (context) => const OSLoginPage(),
                        //   ),
                        // );

                        UserManager.instance.logout();
                        Get.deleteAll(force: true);
                        Get.until((route) => route.isFirst);
                      },
                      child: T.current.me2_log_out.text(
                        fontSize: 18,
                        color: const Color(0xFF1B1B1B),
                        weight: TextFontWeight.regular,
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
